package com.ronghui.cash.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ronghui.cash.entity.UserMsg;
import com.ronghui.cash.parambean.IdBean;
import com.ronghui.cash.service.UserMsgService;
import com.ronghui.cash.vo.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserMsgController extends BaseController {

	@Autowired
	UserMsgService userMsgService;

	/**
	 * 站内信
	 *
	 * @return
	 */
	@RequestMapping("msg")
	public Response msg() {
		Long userId = getUserId();
		Page<UserMsg> page = getPage();
		return success(userMsgService.updateAndGetlistByUserId(page, userId));
	}

	/**
	 * 用户点击未读消息更新为已读
	 *
	 * @return
	 *//*
	@RequestMapping("msgClickUpdate")
	public Response msgClickUpdate_V2_0(@Validated IdBean idBean) {
		UserMsg userMsg = userMsgService.selectById(idBean.getId());
		if(userMsg != null && userMsg.getStatus() == 1){
			userMsg.setStatus(2);
			userMsgService.updateById(userMsg);
		}
		return success();
	}*/

	/**
	 * 设置全部未读消息为已读
	 *
	 * @return
	 */
	@RequestMapping("msgUpdateAll")
	public Response msgUpdateAll_V2_0(@Validated IdBean idBean) {
		Long userId = getUserId();
		userMsgService.updateNewByUserId(userId);
		return success();
	}
}
